package com.epigeon.amadeo.test;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.AttributeSet;

import com.epigeon.amadeo.impl.ActiveButton;
import com.epigeon.amadeo.impl.XMPPConnectionInput;
import com.epigeon.amadeo.model.Message;
import com.epigeon.amadeo.model.StringMessage;
import com.epigeon.amadeo.model.XMPPConnectionMessage;

public class ActiveConnectButton extends ActiveButton {

	public ActiveConnectButton(Context context, AttributeSet attr) {
		super(context, attr);
	}

	@Override
	public Message compose(List<Message> messages) {
		String host = null, port = null, service = null, user = null, password = null;
		
		for (Message message : messages) {
			StringMessage sMessage = (StringMessage) message;
			
			String key = sMessage.getSourceKey();
			String value = sMessage.getValue();
			
			if ( SettingsDialog.TAG_TEXT_HOST.equals(key) ) {
				host = value;
			} else if ( SettingsDialog.TAG_TEXT_PORT.equals(key) ) {
				port = value;
			} else if ( SettingsDialog.TAG_TEXT_SERVICE.equals(key) ) {
				service = value;
			} else if ( SettingsDialog.TAG_TEXT_USER.equals(key) ) {
				user = value;
			} else if ( SettingsDialog.TAG_TEXT_PASSWORD.equals(key) ) {
				password = value;
			}	
		}
		
		return new XMPPConnectionMessage(XMPPConnectionInput.MESSAGE_TYPE_CONNECT, this.getKey(), host, port, service, user, password);
	}

	@Override
	public void setParameters(Map<String, String> parameterMap) {
		// nothing to set here :)
	}

}
